package com.example.blackbox.Adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.blackbox.Data.GameL;
import com.example.blackbox.R;

import java.util.ArrayList;

public class GameLAdapter extends RecyclerView.Adapter<GameLAdapter.ViewHold> {

    private ArrayList<GameL> data=new ArrayList<>();
    private Activity activity;
    public GameLAdapter(ArrayList<GameL> data) {
        this.data = data;
    }

    public GameLAdapter(ArrayList<GameL> data, Activity activity) {
        this.data = data;
        this.activity = activity;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        Log.d("test",viewType+"");
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gamel,parent,false);
        ViewHold viewHold=new ViewHold(view);
        return viewHold;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold holder, int position) {
        GameL game=data.get(position);
        Glide.with(activity).load(game.getGameImg()).into(holder.gameImg);
        holder.gameName.setText(game.getGameName());
        holder.gameTag.setText(game.getGameTag());
        holder.gamePrice.setText(game.getGamePrice());

    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    class ViewHold extends RecyclerView.ViewHolder{

        private ImageView gameImg;
        private TextView gameName;
        private TextView gameTag;
        private TextView gamePrice;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            gameImg = itemView.findViewById(R.id.item_gamel_gameimg);
            gameName = itemView.findViewById(R.id.item_gamel_gamename);
            gameTag = itemView.findViewById(R.id.item_gamel_tag);
            gamePrice = itemView.findViewById(R.id.item_gamel_gameprice);

        }
    }
}

